package leetcode.offer;

import leetcode.common.ListNode;

@SuppressWarnings("all")
public class _24_反转链表_迭代 {

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) return head;
        // 1->2->3->4->5->NULL
        ListNode tempNode;
        ListNode headNode = null;
        while (head != null){
            tempNode = head.next; //保存2        保存3
            head.next = headNode; //1->null     2->1->null
            headNode = head;      //指向1        指向2
            head = tempNode;      //指向2，此时链表为2->3->4->5->null    指向3，此时链表为3->4->5->null
        }
        return headNode;
    }

}
